package com.vincent.kdp.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.vincent.kdp.R;
import com.vincent.kdp.ui.bean.entity.HotCommodity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


public class HotCommoditiesAdapter extends BaseAdapter {
    private ViewHolder holder;
    private List<HotCommodity> mHotCommodityList;
    private Context context;

    public HotCommoditiesAdapter(Context context, List<HotCommodity> mHotCommodityList) {
        this.context = context;
        this.mHotCommodityList = mHotCommodityList;
    }

    @Override
    public int getCount() {
        return mHotCommodityList.size() > 3 ? 3 : mHotCommodityList.size();
    }

    @Override
    public Object getItem(int position) {
        return mHotCommodityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_lv_hot_commodity, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Glide.with(context).load(mHotCommodityList.get(position).getImageUrl()).placeholder(R.mipmap
                .zikjlogo).into(holder.mCommodityImg);
        holder.mCommodityNameTv.setText(mHotCommodityList.get(position).getGoodName());

        holder.mPriceTv.setText("￥" + mHotCommodityList.get(position).getPrice());
        holder.mCompanyAndHandInch.setText("款号："+mHotCommodityList.get(position).getCompanyStyleNum());
        holder.mCompanyAndHandInch2.setText("手寸："+mHotCommodityList.get(position).getHandInch()+"号");
        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.commodity_img)
        ImageView mCommodityImg;
        @Bind(R.id.commodity_name_tv)
        TextView mCommodityNameTv;
        @Bind(R.id.price_tv)
        TextView mPriceTv;
        @Bind(R.id.company_style_num_and_handInch_tv)
        TextView mCompanyAndHandInch;
        @Bind(R.id.company_style_num_and_handInch_tv2)
        TextView mCompanyAndHandInch2;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
